package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.POJO.Permission;
import com.itheima.entity.QueryPageBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface PermissionMapper {

    @Select("select p.* from t_permission p ,t_role_permission rp where p.id = rp.permission_id and rp.role_id = #{roleid}")
    Set<Permission> findBYroleID(Integer roleid);

    @Select("select * from t_permission ")
    List<Permission> getpermissions();

    @Select("select * from t_permission where id in (select permission_id from t_role_permission where role_id=#{id}) ")
    Set<Permission> findPermissionsByRoleId(Integer id);

    @Select("<script>select * from t_permission <where><if test='queryString!=null and queryString.length>0'>name like concat ('%',#{queryString},'%')</if></where></script>")
    Page<Permission> findPermissionByPage(QueryPageBean queryPageBean);

    @Insert("insert into t_permission values(null,#{name},#{keyword},#{description})")
    void addPermisson(Permission permission);
}
